@model iMyRestaurent.Models.ForgotModel
@section import {
    @NoCache.Instance.Css(Url, "~/Content/account.css")
}
@{
    Layout = "~/Views/Shared/_Layout.cshtml";
    ViewBag.Title = "iMyRestaurant - Forgot Password";
}
<div class="landing-container">
    <div class="image-left">
    </div>
    <div class="image-right">
    </div>
    <div id="top-space">
    </div>
    <div class="logo">
    </div>
    <div id="version">
        Version 1.3.83</div>
    <div id="powered-by">
        <span>Powered by </span><span class="vendor-name">iMyVenue applications</span>
    </div>
    <div id="description">
        A major step forward in managing your restaurant and getting customers<br />
        to make table reservations from Smartphone devices or your website.
    </div>
    <div class="opacity-box center-box clearfix" id="form">
        <div class="center-box" id="table-form">
            <form action="@Url.Action(null, null, null)" style="margin-top: 10px;" method="post">
            <div id="error" class="hidden">@ViewBag.Message</div>
            <div class="left field-title">
                <span>Restaurant ID</span>
            </div>
            <div class="left field-input">
                <input type="text" name="RestaurantID" value="@(Model == null ? "" : Model.RestaurantID)" />
            </div>
            <div class="left field-title">
                <span>User (email)</span>
            </div>
            <div class="left field-input">
                <input type="text" name="UserName" value="@(Model == null ? "" : Model.UserName)" />
            </div>
            <div>
                <span>Answer to secret question</span>
            </div>
            <div class="clearfix" style="padding-bottom: 5px;">
                <div class="left" style="height: 28px; width: 280px;">
                    <input type="text" name="SecretAnswer" style="width: 280px; margin-top: 3px;" />
                </div>
                <button type="button" class="image-button button-display-password right">
                </button>
            </div>
            <div class="clearfix" style="padding-bottom: 5px;">
                <div class="left" style="line-height: 28px;">
                    Do you want to get question by email?
                </div>
                <button type="button" class="image-button button-send-question right">
                </button>
            </div>
            <div class="left field-title">
                <span>Password</span>
            </div>
            <div class="left field-input">
                <input type="text" name="NewPassword" />
            </div>
            <input type="submit" name="submitForgot" value="" class="image-button button-login center-box" />
            </form>
        </div>
    </div>
</div>
@section footer {
    <a href="@Url.Action("Login", "Account")" class="button-back image-button left">
    </a>
}
@section script {
    <script language="javascript" type="text/javascript">
        $(document).ready(function () {
            var message = $("#error").text();

            if (message.length > 0) {
                MessageBox.show({
                    message: [message],
                    buttons: {
                        ok: null
                    }
                });
            }
        });

        $(function () {
            $(".button-display-password").click(function () {
                if (validate()) {
                    var answer = $("input[name='SecretAnswer']").val();

                    if ($.trim(answer.length) > 0) {
                        showProgressDialog("Generating new password");
                        $.ajax({
                            type: "post",
                            url: "/Account/DisplayPassword",
                            data: {
                                restId: $.trim($("input[name='RestaurantID']").val()),
                                username: $.trim($("input[name='UserName']").val()),
                                answer: $.trim(answer)
                            },
                            success: function (response) {
                                if (response.IsSucceed) {
                                    $("input[name='NewPassword']").val(response.Password);
                                } else {
                                    MessageBox.show({
                                        message: ["Your answer is incorrect!"],
                                        buttons: {
                                            ok: null
                                        }
                                    });
                                }
                            },
                            complete: function () {
                                hideProgressDialog();
                            }
                        });
                    } else {
                        MessageBox.show({
                            message: ["Your answer is incorrect!"],
                            buttons: {
                                ok: null
                            }
                        });
                    }
                }

                return false;
            });

            $(".button-send-question").click(function () {
                if (validate()) {
                    showProgressDialog("Sending question");
                    $.ajax({
                        type: "post",
                        url: "/Account/SendQuestion",
                        data: {
                            restId: $.trim($("input[name='RestaurantID']").val()),
                            username: $.trim($("input[name='UserName']").val())
                        },
                        success: function (response) {
                            if (!response.IsSucceed) {

                                MessageBox.show({
                                    message: ["Please ensure you have the correct Email address!"],
                                    buttons: {
                                        ok: null
                                    }
                                });
                            }
                        },
                        complete: function () {
                            hideProgressDialog();
                        }
                    });
                }

                return false;
            });
        });

        function validate() {
            var restId = $.trim($("input[name='RestaurantID']").val());
            var username = $.trim($("input[name='UserName']").val());

            return restId.length > 0 && username.length > 0;
        }
    </script>
}
